//
//  NSCountedSet+ZXAvoidCrash.m
//  ZXAvoidCrash
//
//  Created by 朱新明 on 2023/3/23.
//

#import "NSCountedSet+ZXAvoidCrash.h"
#import "ZXAvoidCrashRuntime.h"
#import "ZXAvoidCrashReport.h"

@implementation NSCountedSet (ZXAvoidCrash)

+ (void)zx_avoidCrashExchangeMethod
{
    Class NSCountedSet = NSClassFromString(@"NSCountedSet");
    [ZXAvoidCrashRuntime exchangeInstanceMethodWithClass:NSCountedSet originalSelector:@selector(removeObject:) swizzledSelector:@selector(zx_removeObject:)];
    [ZXAvoidCrashRuntime exchangeInstanceMethodWithClass:NSCountedSet originalSelector:@selector(addObject:) swizzledSelector:@selector(zx_addObject:)];
}


//=================================================================
/*
 - (void)removeObject:(ObjectType)object;
*/
//=================================================================
/*
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCountedSet removeObject:]: object cannot be nil'
 */
- (void)zx_removeObject:(id)object{
    @try {
        [self zx_removeObject:object];
    } @catch (NSException *exception) {
        [ZXAvoidCrashReport crashReportWithException:exception];
    } @finally {
    }
}


//=================================================================
/*
 - (void)addObject:(ObjectType)object;
*/
//=================================================================
//*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCountedSet addObject:]: object cannot be nil'

- (void)zx_addObject:(id)object{
    @try {
        [self zx_addObject:object];
    } @catch (NSException *exception) {
        [ZXAvoidCrashReport crashReportWithException:exception];
    } @finally {
    }
}


@end
